// components/custom-count-down/custom-count-down.js
import moment from '../../tools/moment'
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    //countDown：首页的  detail:详情的 vote:投票的
    countType: {
      type: String,
      value: 'countDown'
    },
    endTimestamp: {
      type: Number,
      value: 0,
    }
  },
  observers: {
    'endTimestamp': function (value) {
      // this.setData({
      //   showPop: value
      // })
      let currentTimestamp = moment().unix();
      console.log('JJLog:当前时间戳：' + currentTimestamp)
      console.log('JJLog:传入的时间戳是:' + value);

      if (value > 0) {
        this.setData({
          timeStamp: (value - currentTimestamp) * 1000
        })
        console.log('JJLog:看看是=====:' + this.data.timeStamp)
      }

    },

  },

  /**
   * 组件的初始数据
   */
  data: {
    timeStamp: 0,//时间戳差值
    timeData: {},
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onChange(e) {
      let detailTime = e.detail;
      detailTime.days = this.dealZero(detailTime.days);
      detailTime.hours = this.dealZero(detailTime.hours);
      detailTime.minutes = this.dealZero(detailTime.minutes);
      detailTime.seconds = this.dealZero(detailTime.seconds);
      this.setData({
        timeData: detailTime,
      });
    },
    dealZero(number) {
      number = number < 10 ? '0' + number : number
      return number;

    },
    timeChange(timeStamp) {

    },
    timeFinish(){
      this.triggerEvent('timeFinish');
    },
  }
})
